package com.urun.interceptor.hotanalysis.service;

import com.urun.interceptor.hotanalysis.DTO.StWordHiddenDTO;
import com.urun.interceptor.hotanalysis.DTO.StWordSearchDTO;
import com.urun.interceptor.hotanalysis.DTO.StWordSortDTO;
import com.urun.interceptor.hotanalysis.bean.StWords;
import com.urun.interceptor.hotanalysis.mapper.db1.StWordsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StWordsService  {
    @Autowired
    StWordsMapper stWordsMapper;

    /**
     * 通过id查找返回当前id的所有字段
     * @param id
     * @return
     */
    public List<StWords> find(Integer id){
        return  stWordsMapper.selectWordById(id);
    }

    /**
     * 通过词频的值来进行排行(倒序排序)
     * @return
     */
    public List<StWordSortDTO> sort(){
        return stWordsMapper.SortFrequency();
    }


    /**
     * 通过id修改当前的NewWord
     * @param newWord
     * @param id
     * @return
     */
    public boolean StNewWordEdit(String newWord,Integer id){
        boolean b = stWordsMapper.UpdateNewWord(newWord,id);
        if (!b){
            throw new RuntimeException();
        }
        return b;
    }

    /**
     * 搜索显示出当前热词
     * @return
     */
    public List<StWordSearchDTO> SearchWordDTO(){
        return stWordsMapper.SearchWordDTO();
    }

    /**
     * 搜索显示出屏蔽热词
     * @return
     */
    public List<StWordSearchDTO> SearchHiddenWordDTO(){
        return stWordsMapper.SearchHiddenWordDTO();
    }

    /**
     * 通过当前热词的Id来修改Status
     */
    public boolean UpdateStatus(Integer id){
        return stWordsMapper.UpdateStatus(id);
    }

    /**
     * 恢复默认键 通过修改全部Status恢复为默认1
     */
    public boolean UpdateDefaultStatus(){
        return stWordsMapper.UpdateDefaultStatus();
    }


    public List<StWordHiddenDTO> search(){
        return stWordsMapper.search();
    }

}
